#pragma once

#include "public/build.h"
#include "core/color.h"

#include <string>

namespace renderit
{
	namespace image
	{
		const uint32 BLOCK_HASH_BLOCKS = 16;
		const uint32 BLOCK_HASH_BITS = BLOCK_HASH_BLOCKS * BLOCK_HASH_BLOCKS;

		class image
		{
		public:
			image();
			~image();

		public:
			void create(uint32 width, uint32 height);
			void release();

			uint32 width() const { return width_; }
			uint32 height() const { return height_; }

			core::color4b * colors() { return colors_; }
			
			core::color4b& get_at(uint32 row, uint32 line)
			{
				if (row >= height_ || line >= width_)
				{
					return dummy_;
				}
				return colors_[row * width_ + line];
			}

			core::color4b& sample(double row, double line)
			{
				uint32 r = row * (width_ - 1);
				uint32 l = line * (height_ - 1);
				return get_at(r, l);
			}
			
		public:
			void set_fpath(const std::string& fpath) { fpath_ = fpath; }
			const std::string& fpath() { return fpath_; }

		public:
			const int * get_blockhash();
			
		private:
			core::color4b * colors_;
			uint32 width_;
			uint32 height_;

			core::color4b dummy_;

			// file data
			std::string fpath_;

			// percepture hash
			int * block_hash_;

			friend uint32 hamming_distance(const image * a, const image * b);
		};

		uint32 hamming_distance(const image * a, const image * b);
	}
}